package cn.jinhe.doc.view.action;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;

import cn.jinhe.doc.base.BaseAction;
import cn.jinhe.doc.domain.Service;
import cn.jinhe.doc.util.QueryHelper;

@Controller
@Scope("prototype")
public class ServiceManageAction extends BaseAction<Service> {
	public String list() throws Exception {
		new QueryHelper(Service.class, "s").addOrderProperty(true, "s.positions", true).preparePageBean(serviceService,
				pageNum, pageSize);

		return "list";
	}

	/*
	 * 删除
	 */
	public String delete() throws Exception {
		serviceService.delete(model.getId());

		return "toList";
	}

	/*
	 * 添加
	 */
	public String add() throws Exception {
		serviceService.save(model);

		return "toList";
	}

	/*
	 * 添加页面
	 */
	public String addUI() throws Exception {
		return "saveUI";
	}

	/*
	 * 修改页面
	 */
	public String editUI() throws Exception {
		Service service = serviceService.getById(model.getId());
		ActionContext.getContext().getValueStack().push(service);
		return "saveUI";
	}

	/*
	 * 修改
	 */
	public String edit() throws Exception {
		Service service =serviceService.getById(model.getId());;
		service.setDescription(model.getDescription());
		service.setName(model.getName());
		serviceService.update(service);
		return "toList";
	}

	public String moveUp() throws Exception {
		serviceService.moveUp(model.getId());
		return "toList";
	}

	/*
	 * 下移
	 */
	public String moveDown() throws Exception {
		serviceService.moveDown(model.getId());
		return "toList";
	}
}
